package com.monkeygroup.mygoplus.common.DefinedView;

import android.text.Editable;
import android.text.TextWatcher;

import android.widget.EditText;
import android.app.Activity;
import android.util.Log;

import com.monkeygroup.mygoplus.commit.thing.vo.PropertyCommitVO;
import com.monkeygroup.mygoplus.common.utils.LocalInfo;
import com.monkeygroup.mygoplus.common.utils.StringUtil;
import com.monkeygroup.mygoplus.common.utils.VilidateUtil;


/**
 * Created by cumt on 2017/5/26.
 */

public class CustomTextWatcher  implements TextWatcher {


    private EditText mEditText;
    private CharSequence mCharSequence;
    private Activity activity;
    private PropertyCommitVO requestVO;
    private int index;
    //租房false，出售true
    private boolean flag=true;

    public CustomTextWatcher(Activity activity,EditText e,PropertyCommitVO vo,int index) {
        mEditText = e;
        this.activity=activity;
        this.requestVO=vo;
        this.index=index;
    }

    public CustomTextWatcher(Activity activity,EditText e,PropertyCommitVO vo,int index,boolean flag) {
        mEditText = e;
        this.activity=activity;
        this.requestVO=vo;
        this.index=index;
        this.flag=flag;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        mCharSequence = s;
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        if(!StringUtil.isBlank(String.valueOf(mEditText.getText()))){
            Log.e("Stringt.getText())==",""+index+"::"+String.valueOf(mEditText.getText()));
            //巷
            if(index==1){
                requestVO.setProperty_alley(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
           else if(index==2){
                requestVO.setProperty_lane(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
           else if(index==3){
                requestVO.setProperty_gate(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            else if(index==4){
                requestVO.setProperty_floor(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            else if(index==5){
                requestVO.setProperty_room(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //售价
            else if(index==6){
                //VilidateUtil.isNumeric(String.valueOf(mEditText.getText()))
                requestVO.setProperty_saleprice(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //楼层
            else if(index==7){
                requestVO.setProperty_minfloor(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //楼高
            else if(index==8){
                requestVO.setProperty_totalfloor(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //坪数
            else if(index==9){
                requestVO.setProperty_ownershiparea(Integer.parseInt(String.valueOf(mEditText.getText())));
            }

            //几房
            else if(index==10){
                requestVO.setProperty_rooms(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            else if(index==11){
                requestVO.setProperty_halls(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            else if(index==12){
                requestVO.setProperty_toilets(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            else if(index==13){
                requestVO.setProperty_offices(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //几阳台
            else if(index==14){
                requestVO.setProperty_balconys(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //描述
            else if(index==15){
                requestVO.setProperty_desc(String.valueOf(mEditText.getText()));
            }
            //管理费
            else if(index==16){
                requestVO.setProperty_fee(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            //面寬
            else if(index==17){
                requestVO.setProperty_width(String.valueOf(mEditText.getText()));
            }
            else if(index==18){
                requestVO.setProperty_height(String.valueOf(mEditText.getText()));
            }
            //段
            else if(index==19){
                requestVO.setProperty_locate1(String.valueOf(mEditText.getText()));
            }
            else if(index==20){
                requestVO.setProperty_locate2(String.valueOf(mEditText.getText()));
            }
            else if(index==21){
                requestVO.setProperty_roadwidth(String.valueOf(mEditText.getText()));
            }
            //车位数量
            else if(index==22){
                requestVO.setProperty_portcnt(Integer.parseInt(String.valueOf(mEditText.getText())));
            }
            if(flag){
                LocalInfo.saveProperty(activity,requestVO);
            }
            else{
                LocalInfo.saveRentProperty(activity,requestVO);
            }
        }
    }
}
